package interfaces.clients.authorization;

import interfaces.clients.dispatcher.commands.NoClassCorrectableDebugException;
import interfaces.clients.dispatcher.commands.ReadCorrectableException;

import java.io.IOException;
import java.io.ObjectInputStream;

/**
 * @author Mihail A. Muhin
 */
public class AuthorizationData {
	private String username = null;

	private String password = null;

	public AuthorizationData() {

	}

	public AuthorizationData(String username, String password) {
		this.username = username;
		this.password = password;
	}

	public String getUsername() {
		return username;
	}

	public String getPassword() {
		return password;
	}

	public void read(ObjectInputStream ois) throws ReadCorrectableException, NoClassCorrectableDebugException {
		try {
			username = (String) (ois.readObject());
			password = (String) (ois.readObject());
		} catch (IOException e) {
			throw new ReadCorrectableException("Authorization failed - couldn't read username or password");
		} catch (ClassNotFoundException e) {
			throw new NoClassCorrectableDebugException("Illegal object in authorization's ObjectInputStream", e);
		}
	}
}
